package hao.test.motan.client;

import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSON;

import hao.test.motan.api.RestfulService;
import hao.test.motan.api.model.User;

/**
 * Created by zhanglei28 on 2017/8/30.
 */
public class RestfulClient {
	public static ApplicationContext ctx;

	@BeforeClass
	public static void initContext() {
		ctx = new ClassPathXmlApplicationContext(new String[] { "classpath:motan_demo_client_restful.xml" });
	}

	@Test
	public void callByRest() {
		RestfulService service1 = (RestfulService) ctx.getBean("restfulReferer");
		List<User> result = service1.getUsers(789);
		print(result);
	}

	@Test
	public void callByMotan() {
		RestfulService service2 = (RestfulService) ctx.getBean("motanReferer");
		List<User> result = service2.getUsers(789);
		print(result);
	}

	private void print(Object result) {
		System.out.println(JSON.toJSONString(result, true));
	}
}
